﻿using SqlScriptVault.Commands;
using SqlScriptVault.Model;
using SqlScriptVault.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlScriptVault.ViewModel
{
    class ServerGroupViewModel
    {
        private readonly IMessageDisplayService _messageDisplayService;

        public ServerGroupViewModel()
            : this(new MessageDisplayService())
        {
        }

        public ServerGroupViewModel(IMessageDisplayService messageDisplayService)
        {
            _messageDisplayService = messageDisplayService;

            ServerGroup = new ServerGroup();
        }

        public ServerGroup ServerGroup { get; private set; }

        public RelayCommand CommitCommand
        {
            get
            {
                return new RelayCommand(param => Commit());
            }
        }

        public event Action RequestClose;

        public void Commit()
        {
            if (string.IsNullOrEmpty(ServerGroup.Name))
            {
                _messageDisplayService.ShowErrorMessage("Name can not be empty.");
                return;
            }

            RequestClose();
        }
    }
}
